package com.study2.A03Test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Random;

public class A03_Test {
    /*
    * 有5个学生
    *   要求点到的不会再被点到
    *   但是如果全被点到了就开启第二轮
    * */
    
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张三", "李四", "王五", "赵六", "钱七");
        ArrayList<String> list2 = new ArrayList<>(list);
        HashMap<String,Integer> map = new HashMap<>();
        Random r = new Random();
        for (int j = 0; j < 10; j++) {
            for (int i = 0; i < list.size(); i++) {
                if(!list2.isEmpty()){
                    int i1 = r.nextInt(list2.size());
                    String name = list2.remove(i1);
                    if(map.containsKey(name)){
                        Integer i2 = map.get(name) + 1;
                        map.put(name, i2);
                    } else {
                        map.put(name, 1);
                    }
                }
                if(list2.isEmpty()){
                    list2.addAll(list);
                }
            }
        }
        System.out.println(map);
    }
}
